//  COOKIE格式
 //   "lc2=58238; lc=58238; wc=71798; wc_n=%25u5EFA%25u90BA%25u533A;";

/**
 * 存 COOKIE
 * @param {String} key 键
 * @param {Object} val 值
 * @param {Number} time 时间，默认10s
 */
function setcookie(key, val, time = 10) {
  //当cookie值是对象，需要使用JSON.stringify转换
  if (typeof val === "object") val = JSON.stringify(val);
  const d = new Date();
  d.setTime(d.getTime() - 1000 * 60 * 60 * 8 + 1000 * 1 * time);
  document.cookie = `${key}=${val}; expires=${d}`;
}

/**
 * COOKIE获取 对应参数的值
 * @param {String} key 键
 * @returns String
 */
function getcookie(key) {
    const arr = document.cookie.split(`; `);
    for (let n = 0; n < arr.length; n++) {
      if (arr[n].split(`=`)[0] === key) return arr[n].split(`=`)[1];
    }
    return `错误，未找到相应的key`;
  }

// /**
//  * COOKIE删除
//  * @param {String} key 键
//  * @returns undefined
//  */
function removecookie(key) {
  //原理：使cookie时间过期
  setcookie(key, null, -1);
}
